package com.naxiang.zhaohang.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.naxiang.zhaohang.interfacs.BackCall;
import com.naxiang.zhaohang.naxiangdiloge.R;

public class DialogUtil {
    /**
     * 单个 确定提示dialgo(确定) showInfoDialog(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选)
     *
     * @param context
     * @return Dialog
     * @since 1.0.0
     */
    public static Dialog showInfoDialog(final Context context, String titel, String content, final BackCall call) {

        final Dialog dlg = new Dialog(context, R.style.noDialogTheme);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout layout = (LinearLayout) inflater.inflate(
                R.layout.dialog_show_info, null);
        TextView title = (TextView) layout.findViewById(R.id.title);
        title.setText(titel);
        TextView cont = (TextView) layout.findViewById(R.id.content);
        cont.setText(content);

        layout.findViewById(R.id.confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dlg.dismiss();
                if (call != null) {
                    call.deal(MunberUtils.CONFIRM, dlg);
                    dlg.dismiss();
                }
            }
        });

        Window w = dlg.getWindow();
        WindowManager.LayoutParams lp = w.getAttributes();
        lp.gravity = Gravity.CENTER;
        dlg.onWindowAttributesChanged(lp);
        dlg.setCanceledOnTouchOutside(true);
        dlg.setContentView(layout);
        dlg.setCancelable(false);
        return dlg;

    }
    /**
     * 两个按键（确定，取消）的dialog showInfoDialog1(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选)
     *
     * @param context
     * @param call
     * @return Dialog
     * @since 1.0.0
     */
    public static Dialog showInfoDialogTwo(final Context context, String titel,
                                         String content, String conf, String canc, final BackCall call) {
        final Dialog dlg = new Dialog(context, R.style.PushUpInDialogThem);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout layout = (LinearLayout) inflater.inflate(
                R.layout.dialog_show_info1, null);
        TextView title = (TextView) layout.findViewById(R.id.title);
        title.setText(titel);
        TextView cont = (TextView) layout.findViewById(R.id.content);
        cont.setText(content);
        TextView confirm = (TextView) layout.findViewById(R.id.confirm);
        confirm.setText(conf);
        TextView cancel = (TextView) layout.findViewById(R.id.cancel);
        cancel.setText(canc);

        layout.findViewById(R.id.confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (call != null) {
                    call.deal(MunberUtils.CONFIRM, dlg);
                    dlg.dismiss();
                } else {
                    dlg.dismiss();
                }
            }
        });
        layout.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (call != null) {
                    call.deal(MunberUtils.CANCEL, dlg);
                    dlg.dismiss();
                } else {
                    dlg.dismiss();
                }
            }
        });
        Window w = dlg.getWindow();
        WindowManager.LayoutParams lp = w.getAttributes();
        lp.gravity = Gravity.CENTER;
        dlg.onWindowAttributesChanged(lp);
        dlg.setCanceledOnTouchOutside(true);
        dlg.setContentView(layout);
        dlg.setCancelable(false);
        dlg.show();
        return dlg;
    }

    /**
     * 单个 确定提示dialgo(确定) showInfoDialog(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选)
     *
     * @param context
     * @return Dialog
     * @since 1.0.0
     */
    public static Dialog showPayDialog(final Context context, String titel, String content) {

        final Dialog dlg = new Dialog(context, R.style.noDialogTheme);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout layout = (LinearLayout) inflater.inflate(
                R.layout.dialog_show_pay, null);
        TextView title = (TextView) layout.findViewById(R.id.title);
        title.setText(titel);
        TextView cont = (TextView) layout.findViewById(R.id.content);
        cont.setText(content);

        layout.findViewById(R.id.confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dlg.dismiss();
            }
        });

        Window w = dlg.getWindow();
        WindowManager.LayoutParams lp = w.getAttributes();
        lp.gravity = Gravity.CENTER;
        dlg.onWindowAttributesChanged(lp);
        dlg.setCanceledOnTouchOutside(true);
        dlg.setContentView(layout);
        dlg.setCancelable(false);
        return dlg;

    }
}
